<!--
 * @Description  : 
 * @Autor        : guoxi
 * @Date         : 2022-07-27 14:41:41
 * @LastEditors  : Please set LastEditors
 * @LastEditTime : 2022-09-13 16:31:45
 * @FilePath     : \rpms\src\views\project\detail\components\descTabs\tab6.vue
-->
<template>
  <div class="content">
    <el-table
      :data="model.tableData"
      border
      style="width: 100%"
      v-loading="loading"
      :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
    >
      <template #empty>
        <el-empty :image-size="150" description="暂无数据"></el-empty>
      </template>
      <el-table-column type="index" label="序号">
        <template v-slot="scope">
          <span>{{
            (pageState.pageNum - 1) * pageState.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="kyNum" label="编号" width="180"> </el-table-column>
      <el-table-column prop="kyName" label="成果名称"> </el-table-column>

      <el-table-column prop="createUserName" label="创建人"> </el-table-column>
      <el-table-column prop="createTime" label="创建时间" min-width="100">
      </el-table-column>
      <el-table-column prop="kyTypeCode" label="成果类型">
        <template #default="{ row }">
          {{ model.types.find(el => el.dicCode === row.kyTypeCode).dicValue }}
        </template>
      </el-table-column>
      <el-table-column prop="projectPhaseName" label="成果来源">
        <template #default="{ row }">
          {{ row.projectManageId ? "项目" : "非项目" }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="80">
        <template #default="{ row }">
          <el-button type="text" size="small" @click="jump(row)"
            >查看详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <re-pagination
      v-if="model.total > 0"
      :total="model.total"
      v-model:page="pageState.pageNum"
      v-model:limit="pageState.pageSize"
      @pagination="handleChangePage"
    />
  </div>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from "vue";
import { useRoute } from "vue-router";

import { postScientificList } from "/@/api/scientific";
// const props = defineProps({
//   projectInfo: {
//     type: Object
//   }
// });
const route = useRoute();
const loading = ref(false);
const model = reactive({
  tableData: [],
  total: 0,
  types: [
    { dicCode: "1", dicValue: "专利" },
    { dicCode: "2", dicValue: "论文" },
    { dicCode: "3", dicValue: "专著" },
    { dicCode: "4", dicValue: "标准" },
    { dicCode: "5", dicValue: "科技奖励" },
    { dicCode: "6", dicValue: "科技制度建设" },
    { dicCode: "7", dicValue: "软件著作权" },
    { dicCode: "8", dicValue: "其他" }
  ]
});
const formInline = ref({
  kyName: "",
  type: "",
  source: "",
  createUserName: "",
  createTime: "",
  createTimeStrStart: "",
  createTimeStrEnd: "",
  projectManageId: ""
});

const jump = item => {
  const local = location.href.split("#")[0];
  let path = "";
  switch (item.kyTypeName) {
    case "专利":
      path = "#/document/scientific/patent";
      break;
    case "软件著作":
      path = "#/document/scientific/software";
      break;
    case "论文":
      path = "#/document/scientific/paper";
      break;
    case "专著":
      path = "#/document/scientific/book";
      break;
    case "标准":
      path = "#/document/scientific/standard";
      break;
    case "科技奖励":
      path = "#/document/scientific/award";
      break;
    case "科技制度建设":
      path = "#/document/scientific/building";
      break;
    default:
      path = "#/document/scientific/other";
      window.open(
        `${local}${path}?id=${item.id}&projectNum=${item.projectManageCode}&mode='look'`
      );
      return;
  }

  window.open(
    `${local}${path}?id=${item.kyId}&projectNum=${item.projectManageCode}&mode='look'`
  );
};

const pageState = reactive({
  pageNum: 1,
  pageSize: 10
});

const getTableList = async () => {
  try {
    loading.value = true;
    const { code, data } = await postScientificList({
      ...formInline.value,
      ...pageState
    });
    if (code === 200) {
      model.tableData = data.list;
      model.total = data.rows;
    }
  } catch (err) {
    console.log(err);
  } finally {
    loading.value = false;
  }
};

onMounted(() => {
  formInline.value.projectManageId = route.query.id as any;
  getTableList();
});
</script>

<style lang="scss" scoped>
.content {
  min-height: 153px;
  .btnClass {
    margin-bottom: 8px;
  }
}
</style>
